<template>
	<view>
		<u-toast ref="uToast" />
		<view v-if="show" class="loading_view" style="padding:220rpx 0;">
		  <u-loading mode="circle" size="50"></u-loading>
		  <view class="messgae">
			加载中...
		  </view>
		 </view>
		<view class='list' v-for="(v,k) in list" :key="k" @click="onUrl" data-url="/pages/user/userInfo?id=" :data-get="v.u_id">
			<view class="img">
				<image :src='v.u_icon'></image>
			</view>
			<view class='right'>
				<view class='name'>
					<view class="n">
						<text class="hg" v-if="v.u_supremeTime==1">{{v.u_nickname}}</text>
						<text class="hy" v-else-if="v.u_memberTime==1">{{v.u_nickname}}</text>
						<text v-else>{{v.u_nickname}}</text>
						<image src="../../static/image/hg.png" v-if="v.u_supremeTime==1"></image>
						<image src="../../static/image/hy.png" v-else-if="v.u_memberTime==1"></image>
					</view><!-- 
					<view class='range'>300米内</view> -->
				</view>
				<view class='qt'>
					<view class='age'>{{v.u_age}}</view>
					<view class='xz'>{{v.u_star}}</view>
				</view>
				<view class='info' v-if="v.u_hobby.length>0">
					喜欢<text v-for="(n,m) in v.u_hobby" :key="m">{{n}}</text>
				</view>
				<view class="info" v-else>
					回头告诉你
				</view>
			</view>
		</view>
		<view v-if="showError!=''" class='empty'>
			<u-loading mode="circle" v-if='load' size="50"></u-loading>
			<text>{{showError}}</text>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				page:1,
				allpage:1,
				list:[],
				show:true,
				load:false,
				showError:''
			}
		},onLoad(){
			this.onList(1);
		},onReachBottom(){
			var page=this.page;
			
			if(page<this.allpage){
				this.load=true;
				
				this.showError='加载中...';
				
				page++;
			}else{
				this.showError='暂无更多了~';
				return;
			}
			
			this.onList(page);
		},
		onPullDownRefresh() {
			uni.startPullDownRefresh();
			
			this.show=true;
			
			this.showError='';
			
			this.list=[];
			
			this.onList(1);
		},methods:{
			onUrl(e){
				var url=e.currentTarget.dataset.url;
				
				var get=e.currentTarget.dataset.get;
				
				uni.navigateTo({
				    url: url+get
				});
			},
			onList(page=1){
				var that=this;
				
				var sex=1;
				
				uni.getStorage({
					key: 'user_sex',
					success: function (res) {
						if(res.data){
							sex=res.data;
						}
					}
				});
				
				this.$request({
					url:'/nearby/index',
					data:{page:page,sex:sex},
					success(res){
						if(res.data.code==1){
							that.page=res.data.data.page;
							
							that.allpage=res.data.data.allpage;
							
							let list=res.data.data.list;
							
							for(var i in list){
								that.list.push(list[i]);
							}
							
							that.show=false;
							
							that.load=false
							
							that.showError='';
							
							if(that.page>=that.allpage){
								that.showError='暂无更多了~'
							}
						}else{
							that.show=false;
							
							that.showError=res.data.msg;
						}
					},fail(){
						that.$refs.uToast.show({
							title: '网络繁忙',
							type: 'warning'
						})
					}
				})
			}
		}
	}
</script>

<style scoped src='../../static/css/nearby.css'>
</style>
